package com.ss.web.tagmark.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Transient;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

@Entity
public class User implements Serializable, UserDetails {
	private static final long serialVersionUID = -1736826174352249597L;
	/** 状态：正常 */
	public static final String STATUS_ACTIVE = "1";
	/** 状态：离职 */
	public static final String STATUS_INACTIVE = "2";
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long userId;
	@Column
	private String logname;
	@Column
	private String password;
	@Column
	private String fullname;
	@Column
	private String fullnamePy;
	@Column
	private String fullnamePyShort;
	@Column
	private String status;

	// @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	// @JoinTable(name = "user_tag", joinColumns = @JoinColumn(name = "userId"), inverseJoinColumns = @JoinColumn(name =
	// "tagId"))
	@Transient
	private List<TagInfo> tags;

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public String getLogname() {
		return logname;
	}

	public void setLogname(String logname) {
		this.logname = logname;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getFullname() {
		return fullname;
	}

	public void setFullname(String fullname) {
		this.fullname = fullname;
	}

	public String getFullnamePy() {
		return fullnamePy;
	}

	public void setFullnamePy(String fullnamePy) {
		this.fullnamePy = fullnamePy;
	}

	public String getFullnamePyShort() {
		return fullnamePyShort;
	}

	public void setFullnamePyShort(String fullnamePyShort) {
		this.fullnamePyShort = fullnamePyShort;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public List<TagInfo> getTags() {
		return tags;
	}

	public void setTags(List<TagInfo> tags) {
		this.tags = tags;
	}

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return null;
	}

	@Override
	public String getUsername() {
		return getLogname();
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return STATUS_ACTIVE.equals(getStatus());
	}
}
